//
//  NSString+XHSHA_1.m
//  24_加密
//
//  Created by 徐昊 on 16/8/16.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "NSString+XHSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (XHSHA_1)

- (NSString *)stringWithSHA_1 {
    // 1. 返回C语言字符串
    const char *cString = [self UTF8String];
    // 2. 求长度
    CC_LONG len = (CC_LONG)strlen(cString);
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    // 3. SHA_1转换
    CC_SHA1(cString, len, bytes);
    NSMutableString *finalSHA1 = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
    for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
        [finalSHA1 appendFormat:@"%02x", bytes[i]];
    }
    return @"";
}

@end
